const path = require('path')

function resolve(dir) {
  return path.join(process.cwd(), '.', dir)
}
module.exports = {
  /*
  ** Headers of the page
  */
  head: {
    title: '容器云-开发平台',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: 'Nuxt.js project' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
    // script: [
    //   { src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js' }
    // ]
  },
  /*
  ** Global CSS
  */
  css: ['~assets/css/main.css'],
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#3B8070' },
  /*
  ** plugins
  */
  plugins: [{
    src: '~plugins/zlst-sdk.js',
    ssr: true
  }],
  /**
   * 路由配置
   */
  router: {
    middleware: 'auth'
  },
  /*
   ** Build configuration
   */
  build: {
    analyze: false,  // 开启生成代码分析
    // babel配置
    babel: {
      'presets': [
        ['env', {
          'modules': false,
          'targets': {
            'browsers': ['> 1%', 'last 2 versions', 'not ie <= 8']
          }
        }],
        'stage-2'
      ],
      'plugins': ['transform-vue-jsx', 'transform-runtime', 'syntax-dynamic-import'],
      'env': {
        'test': {
          'presets': ['env', 'stage-2'],
          'plugins': ['transform-vue-jsx', 'istanbul']
        }
      }
    },
    /*
     ** Run ESLINT on save
     */
    extend(config, ctx) {
      config.module.rules.find((rule) => {
        if (rule.test.toString().indexOf('(png|jpe?g|gif|svg)') !== -1) {
          rule.exclude = [resolve('icons')]
          config.module.rules.push({
            test: /\.svg$/,
            loader: 'svg-sprite-loader',
            include: [resolve('icons')],
            options: {
              symbolId: 'icon-[name]'
            }
          })
        }
      })
      if (ctx.isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    }
  }
}
